package com.jjvu.news.service.impl;

import com.github.pagehelper.PageHelper;
import com.jjvu.news.dao.Info;
import com.jjvu.news.domain.InfoDao;
import com.jjvu.news.domain.InfoDetailDao;
import com.jjvu.news.service.InfoDetailService;
import com.jjvu.news.util.DelHTMLTag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service("infoDetailService")
public class InfoDetailServiceImpl implements InfoDetailService {
    @Autowired
    private InfoDetailDao infoDetailDao;
    @Autowired
    private DelHTMLTag delHTMLTag;
    public List<Info> findInfoAll() {
        return infoDetailDao.findInfoAll();
    }

    public List<Info> findInfoPageAll(Integer page, Integer size) {
        PageHelper.startPage(page,size);
        List<Info> infoAll = infoDetailDao.findInfoAll();
        for (Info info:infoAll){
            String content = info.getContent();
         //出去content中的HTML标签
            String newContent=delHTMLTag.delHTMLTag(content);
            info.setContent(newContent);
        }
        return infoAll;
    }

    public Info findInfoById(Integer info_id) {
        return infoDetailDao.findInfoById(info_id);
    }

    public boolean updateInfo(Info info) {
        Integer hits=100;
        info.setHits(hits);
        boolean updateInfo = infoDetailDao.updateInfo(info);
        return updateInfo;
    }

    public Info findNameByInfoId(Integer info_id) {
        return infoDetailDao.findNameByInfoId(info_id);
    }

    public boolean addInfo(Info info) {
        Integer hits=100;
        info.setHits(hits);
        return infoDetailDao.addInfo(info);
    }

    public boolean deleteInfo(List<Integer> deviceIds) {
        boolean delInfo=false;
        for (Integer i:deviceIds){
            delInfo=infoDetailDao.deleteInfo(i);
        }
        return delInfo;
    }
}
